# -*- coding: utf-8 -*-
from django.conf.urls.defaults import *
from django.contrib import admin
from django.views.generic.base import *
import dbindexer
#from ragendja.urlsauto import urlpatterns
#from ragendja.auth.urls import urlpatterns as auth_patterns
from astoundlearning_app import views

handler500 = 'djangotoolbox.errorviews.server_error'

# django admin
admin.autodiscover()

# search for dbindexes.py in all INSTALLED_APPS and load them
dbindexer.autodiscover()

urlpatterns = patterns('astoundlearning_app.views',
    (r'^$', views.html_wrapper(views.display_home_page_html),{'template': 'index.html'}),
    (r'^ajax/set/newform.html$',views.html_wrapper(views.set_new_form_html),{'template': 'ajax/addsetform.html'}),
    (r'^ajax/set/study.html$',views.html_wrapper(views.set_study_html),{'template': 'ajax/study.html'}),
    (r'^ajax/set/listViewSearch.html$',views.html_wrapper(views.set_list_view_search_html),{'template': 'ajax/listViewSearchResultTable.html'}),
    (r'^ajax/set/studyViewSearch.html$',views.html_wrapper(views.set_study_view_search_html),{'template': 'ajax/entriesSearch.html'}),
    (r'^ajax/set/unsubscribe.html$',views.html_wrapper(views.set_unsubscribe_html),{'template': 'ajax/setUnsubscribe.html'}),
    (r'^ajax/set/subscribe.html$',views.html_wrapper(views.set_subscribe_html),{'template': 'ajax/setSubscribe.html'}),
    (r'^ajax/set/share.html$',views.html_wrapper(views.set_share_html),{'template': 'ajax/sharing.html'}),
    (r'^ajax/set/displayStudyMaterials.html$',views.html_wrapper(views.set_display_study_materials_html),{'template': 'ajax/studyMaterials.html'}),
    (r'^ajax/set/browserPlugin.html$',views.html_wrapper(views.set_render_browser_plugin_tab_html),{'template': 'ajax/browserPlugin.html'}),
    (r'^ajax/set/displayEditForm.html$',views.html_wrapper(views.set_display_edit_form_html),{'template': 'ajax/editSet.html'}),
    (r'^ajax/set/displayContributors.html$',views.html_wrapper(views.set_display_contributors_html),{'template': 'ajax/contributors.html'}),
    (r'^ajax/set/search.html$',views.html_wrapper(views.set_search_html),{'template': 'ajax/search.html'}),
    (r'^set/study.html$',views.html_wrapper(views.set_study_non_ajax_html),{'template': 'astoundlearning_app/study_non_ajax.html'}),
    (r'^tos.html$',views.display_page_html,{'template': 'astoundlearning_app/tos.html'}),
    (r'^test.html$',views.display_page_html,{'template': 'astoundlearning_app/test.html'}),
    (r'^contact.html$',views.display_page_html,{'template': 'astoundlearning_app/contact.html'}),
    (r'^ourFeedback/send.html$',views.html_wrapper(views.ourFeedback_send_html),{'template': 'astoundlearning_app/ourFeedback_sent.html'}),
    (r'^faq.html$',views.display_page_html,{'template': 'astoundlearning_app/faq.html'}),
    (r'^canvas.html$',views.display_page_html,{'template': 'astoundlearning_app/google-friend-connect/canvas.html'}),
    (r'^rpc_relay.html$',views.display_page_html,{'template': 'astoundlearning_app/google-friend-connect/rpc_relay.html'}),
    (r'^authenticated.html$',views.html_wrapper(views.display_authenticated_page),{'template': 'astoundlearning_app/authenticated.html'}),
    (r'^preferences$',views.html_wrapper(views.display_preferences_page),{'template': 'astoundlearning_app/preferences.html'}),
    (r'^preferences/save.json$',views.json_wrapper(views.save_preferences_json)),
    (r'^preferences/add_location.json$',views.json_wrapper(views.add_location_json)),
    (r'^preferences/display_location_decks.json$',views.json_wrapper(views.display_location_decks_json)),
    (r'^preferences/delete_location.json$',views.json_wrapper(views.delete_location_json)),
    (r'^preferences/save_location_decks.json$',views.json_wrapper(views.save_location_decks_json)),
    (r'^plugin/displayInTab.html$',views.html_wrapper(views.just_display_the_template_html),{'template': 'astoundlearning_app/blank.html'}),
    (r'^plugin/login.json$',views.json_wrapper(views.plugin_login_json)),
    (r'^plugin/peek.json$',views.json_wrapper(views.plugin_peek_json)),
    (r'^plugin/record_entry_displayed.json$',views.json_wrapper(views.plugin_record_entry_displayed_json)),
    (r'^plugin/mark_not_applicable.json$',views.json_wrapper(views.plugin_mark_not_applicable_json)),
    (r'^plugin/get_cards_for_deck.json$',views.json_wrapper(views.plugin_get_cards_for_deck_json)),
    (r'^plugin/locations.json$',views.json_wrapper(views.plugin_locations_json)),
    (r'^dynamic/social.xml$',views.xml_wrapper(views.display_social_xml),{'template': 'astoundlearning_app/social.xml'}),
    (r'^dynamic/javascript.js$',views.serve_social_javascript),
    (r'^style.css$',views.serve_combined_css_without_social),
    (r'^javascript.js$',views.serve_combined_javascript_without_social),
    (r'^setlist.json$',views.json_wrapper(views.setlist_json)),
    (r'^ajax/set/subscribe.json$',views.json_wrapper(views.set_subscribe_json)),
    (r'^social/user/updateDisplayName.json$',views.json_wrapper(views.social_user_update_display_name_json)),
    (r'^set/import.json$',views.set_import_json),
    (r'^set/export.csv$',views.set_export_csv),
    (r'^set/print.html$',views.html_wrapper(views.set_print_html),{'template': 'astoundlearning_app/set_print.html'}),
    (r'^decks/search.html$',views.html_wrapper(views.search_decks_html),{'template': 'astoundlearning_app/search_decks.html'}),
    (r'^deck/create-form.html$',views.html_wrapper(views.deck_create_form_html),{'template': 'astoundlearning_app/deck_create_form.html'}),
    (r'^deck/create-save.html$',views.html_wrapper(views.deck_create_save_html),{'template': 'astoundlearning_app/deck_create_save.html'}),
    (r'^deck/display-edit-form.html$',views.html_wrapper(views.deck_display_edit_form),{'template': 'astoundlearning_app/deck_display_edit_form.html'}),
    (r'^deck/edit-save.html$',views.html_wrapper(views.deck_edit_save_html),{'template': 'astoundlearning_app/redirected.html'}),
    (r'^deck/display_feedback_form.html$',views.html_wrapper(views.deck_display_feedback_form_html),{'template': 'astoundlearning_app/deck_display_feedback_form.html'}),
    (r'^library/delete_not_authored_decks.json$',views.json_wrapper(views.library_delete_not_authored_decks_json)),
    (r'^library/delete_authored_decks.json$',views.json_wrapper(views.library_delete_authored_decks_json)),
    (r'^library.html$',views.html_wrapper(views.display_personal_library_html),{'template': 'astoundlearning_app/personal_library.html'}),
    (r'^deck/subscribe_withoutsetlist.json$',views.json_wrapper(views.deck_subscribe_withoutsetlist_json)),
    (r'^deck/unsubscribe_withoutsetlist.json$',views.json_wrapper(views.deck_unsubscribe_withoutsetlist_json)),
    (r'^set/add.json$',views.json_wrapper(views.set_add_json)),
    (r'^set/study.json$',views.json_wrapper(views.set_study_json)),
    (r'^set/render.json$',views.json_wrapper(views.set_render_json)),
    (r'^set/save.json$',views.json_wrapper(views.set_save_json)),
    (r'^set/save_objective.json$',views.json_wrapper(views.save_objective_json)),
    (r'^ajax/set/info.json$',views.json_wrapper(views.set_info_json)),
    (r'^set/sendFeedback.json$',views.json_wrapper(views.set_send_feedback_json)),
    (r'^set/removeContributors.json$',views.json_wrapper(views.set_remove_contributors_json)),
    (r'^set/searchForPotentialContributors.json$',views.json_wrapper(views.set_search_for_potential_contributors_json)),
    (r'^set/addContributors.json$',views.json_wrapper(views.set_add_contributors_json)),
    (r'^set/reorderEntries.json$',views.json_wrapper(views.set_reorder_entries_json)),
    (r'^ourFeedback/send.json$',views.json_wrapper(views.our_feedback_send_json)),
    (r'^tag/add.json$',views.json_wrapper(views.tag_add_json)),
    (r'^tag/delete.json$',views.json_wrapper(views.tag_delete_json)),
    (r'^tags/delete.json$',views.json_wrapper(views.tags_delete_json)),
    (r'^entry/add.json$',views.json_wrapper(views.entry_add_json)),
    (r'^entry/get.json$',views.json_wrapper(views.entry_get_json)),
    (r'^entry/update.json$',views.json_wrapper(views.entry_update_json)),
    (r'^entry/delete.json$',views.json_wrapper(views.entry_delete_json)),
    (r'^delete_cards.json$',views.json_wrapper(views.delete_cards_json)),
    (r'^entry/deleteTag.json$',views.json_wrapper(views.entry_delete_tag_json)),
    (r'^entry/addTag.json$',views.json_wrapper(views.entry_add_tag_json)),
    (r'^entry/processShowAnswer.json$',views.json_wrapper(views.entry_process_show_answer_json)),
    (r'^robots.txt$',views.robots_dot_txt),
    (r'^tooltips_speechbubble.txt$',views.txt_wrapper(views.send_tooltips_speechbubble_txt),{'template': 'astoundlearning_app/tooltips_speechbubble.txt'}),
    (r'^maintenance$',views.maintenance),
) + patterns('',
    (r'^noscript.html$', TemplateView.as_view(template_name='astoundlearning_app/noscript.html')),
    (r'^favicon.ico$', RedirectView.as_view(url='/images/bellfavicon.ico')),
)

if (False):
    admin.autodiscover()

    handler500 = 'ragendja.views.server_error'

    extra_context = {
	'combinedCSS': combineCSS(), 
	'siteName': 'AstoundLearning'
    }

    urlpatterns = patterns('',
	(r'^$', TemplateView.as_view(template_name='index.html', extra_context= extra_context)),
    )

    urlpatterns = auth_patterns + patterns('',
	('^admin/(.*)', admin.site.root),
	(r'^$', TemplateView.as_view(template_name='main.html')),
	# Override the default registration form
	url(r'^account/register/$', 'registration.views.register',
	    kwargs={'form_class': UserRegistrationForm},
	    name='registration_register'),
    ) + urlpatterns
